<?php

/**
 * Haefko - your php5 framework
 *
 * @author      Jan Skrasek <skrasek.jan@gmail.com>
 * @copyright   Copyright (c) 2008, Jan Skrasek
 * @link        http://haefko.programujte.com
 * @version     0.7
 * @package     Haefko
 */

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="robots" content="noindex,noarchive" />
    <meta name="generator" content="Háefko - your php5 framework" />
    <title>Exception: <?= htmlspecialchars($exception->getMessage()) ?></title>
    <style type="text/css" media="screen">
    body { background: #f6f6f6; font-family: Calibri, sans-serif; padding: 0; margin: 0; }
    a { color: #6F071E; text-decoration: none; font-weight: bold; }
    a:hover { text-decoration: underline; }
    h1 { background: #6F071E; color: white; font-size: 28px; margin: 0; padding: 15px 20px; }
    pre, code { font-family: Consolas, 'Lucida Console', 'Monaco CE', fixed, monospace; font-size: 14px; }
    pre { background: white; border: 1px solid #dedede; padding: 2px; overflow: auto; }
    span.line { color: black; margin: 0 4px; }
    span.cur-line { background: #EFD1D1; }
    </style>
</head>
<body>
<h1><?= $exception->getMessage(); ?></h1>
<?php

$trace = $exception->getTrace();

foreach ($trace as $i => $item) {
    if (isset($item['file']) && !preg_match('#dibi|haefko#i', $item['file']))
        break;
}

$file  = explode('<br />', highlight_file($trace[$i]['file'], true));
$line  = $trace[$i]['line'];
$lines = strlen((string) count($file)) + 1;

foreach ($file as $l => & $row) {
    $row = str_replace("\n", '', $row);

    if ($l == $line - 1) {
        preg_match('#.*(<span[^>]+>)#', $row, $match);
        if (!empty($match[1]))
                $match[1] = '</span>' . $match[1];
        $row = '<span class="cur-line">' . strip_tags($row) . "</span>$match[1]";
    }

    $row = '<span class="line">' . str_pad($l + 1, $lines, " ", STR_PAD_LEFT) . ":</span>$row";
}

$file = implode("", $file);

?>

<div style="padding: 10px 20px;">
    <br />
    <strong>Soubor: </strong> <?= str_replace($_SERVER['DOCUMENT_ROOT'], '', str_replace('\\', '/', $trace[$i]['file'])) ?><br />
    <strong>Řádek: </strong><?= $line ?>
    <pre><?= $file ?></pre>

    <p>
        Čas generování: <strong><?= self::getTime() ?>ms</strong><br />
        Server: <strong><?= $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] ?></strong><br />
        Vygenerováno: <strong><?= date('d.m.Y, h.i') ?></strong><br />
        Powered by: <a href="http://haefko.programujte.com">Háefko</a> v.<?= Application::$version ?><br />
    </p>
</div>
</body>
</html>